package com.yijianonghu.controller.wxwebsite.huodong;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yijianonghu.dal.model.SysBlog;
import com.yijianonghu.service.wxwebsite.huodong.HuoDongProductListService;
import com.yijianonghu.util.Constants;
import com.yijianonghu.util.exception.NoResultReturnedException;
import com.yijianonghu.util.exceptionhandler.ControllerExceptionHandler;
import com.yijianonghu.util.result.MessageCode;
import com.yijianonghu.util.result.Result;

@Controller
@RequestMapping(value=Constants.WXConstants.WX_PREFIX+"huodong/", method=RequestMethod.POST)
public class HuoDongController {
	
	private static final Logger logger=LoggerFactory.getLogger(HuoDongController.class);
	
	@Autowired
	private ControllerExceptionHandler exceptionHandler;
	
	@Autowired
	private HuoDongProductListService huodongProductListService;
	
	@RequestMapping(value="getGWSLPListByteType")
	public @ResponseBody Result getGWSLPListByteType(Integer typeId, String orderBy, Integer offset, Integer limit){
		Result result=new Result();		
		result.setSuccess(false);
		List<SysBlog> list=null;
		try {
			list = huodongProductListService.getGWSLPProductListByteTypeId(typeId, orderBy, offset, limit);
			if(list==null || list.isEmpty()){
				throw new NoResultReturnedException("购物送粮票产品列表为空！购物送粮票分类:"+typeId);
			}
		} 
		catch (NoResultReturnedException e) {
			exceptionHandler.handleException(logger, "购物送粮票产品列表为空！购物送粮票分类:"+typeId, result, MessageCode.WX_NO_RESULT_RETURNED, e);
		}catch (Exception e) {
			exceptionHandler.handleException(logger, "获取购物送粮票产品列表列表失败！购物送粮票分类:"+typeId, result, MessageCode.SYSTEM_BUSY, e);
		} 
		if(list!=null && (!list.isEmpty())){
			result.setInfor(list);
			result.setSuccess(true);
		}
		return result;
	}
}
